import {UploadImgParams} from "../../types/requestTypes";
import {UploadRET} from "../../types/responseTypes";
import request from "../request";
const BASE_URL = import.meta.env.VITE_PIC_URL

/**
 * 上传图片
 * @param params
 */
export const uploadImg = (params: UploadImgParams): Promise<UploadRET> => new Promise((resolve, reject) => {
    uni.showLoading({
        title: '正在上传'
    })
    const {filePath, FLAG, CUSER_ID} = params
    uni.uploadFile({
        url: BASE_URL + '/upload',
        filePath,
        name: 'file',
        formData: {
            FLAG,
            CUSER_ID
        },
        success: (result) => {
            resolve(JSON.parse(result.data))
        },
        fail: (err) => {
            reject(err)
        },
        complete: () => {
            uni.hideLoading()
        }
    })
})

/**
 * 删除图片
 * @param name
 */
export const deleteImg = (name: string) => request.post( '/pic_server/delete', {
    picfilename: name
})
